<template>
  <div>
    <div class="flex">
      <div class="shop-left">
        <div class="shop-head flex">
          <div class="flex">
            <pt-upload  class="up-img" :size="0.5" :upLoadImg="shop.imgpath" @getUpLoad="getUpLoad" />
            <div class="shop-word">
              <div class="name">{{shop.name}}</div><div class="c-time">创建时间：{{shop.createtime}}</div>
            </div>
          </div>
          <div style="font-weight: 600;">开启/关闭营业：<el-switch v-model="shop.statu" @change="doBusinessStateClick()" /></div>
        </div>
        <div class="basic">
          <div class="head flex-row"><span>基本信息</span><el-button type="danger" size="mini" @click="setBasicMsg()">编辑</el-button></div>
          <ul class="main">
            <li class="flex"><span class="column">商户名称:</span><span class="show">{{shop.name}}</span></li>
            <li class="flex"><span class="column">营业状态:</span><span class="show">{{shop.statu?'正在营业':'暂停营业'}}</span></li>
            <li class="flex"><span class="column">外卖电话:</span><span class="show">{{shop.wmMobile}}</span></li>
            <li class="flex"><span class="column">商家电话:</span><span class="show">{{shop.mobile}}</span></li>
            <li class="flex"><span class="column">商户类型:</span>
              <span class="show">{{shop.mainClassName|capitalize(shop.subClassName1,shop.subClassName2)}}</span>
            </li>
            <li class="flex">
              <span class="column">工&nbsp;&nbsp;作&nbsp;&nbsp;日:</span> <span>{{shop.worktoday|capitalize1}}</span>
            </li>
            <li class="flex-row"><span class="column">营业时间:</span>
              <div>{{shop.firstTime|businessHours(shop.secondTime,shop.thirdTime)}}</div>
            </li>
            <li class="flex"><span class="column">商户简介:</span><span class="show">{{shop.content}}</span></li>
            <!--<li class="flex"><span class="column">商户公告:</span><span class="show">{{shop.content}}</span></li>-->
            <li class="flex"><span class="column">订单模式:</span><span class="show">支持网络订单</span></li>
            <li class="flex"><span class="column">门店地址:</span>
              <div class="show map-wrap flex">
                <span>{{shop.provinceName}}{{shop.cityname}}{{shop.countyname}}{{shop.address}}</span>
                <div id="container" class="map-location" style="height: 400px"></div>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div class="shop-right">
        <div class="root">
          <div class="head flex-row"><span>收费策略</span>
            <el-button type="danger" @click="setDistribution()" size="mini">编辑</el-button>
          </div>
          <div class="msg flex">
            <span class="item flex"><span class="ti">是否有效商户：</span>{{shop.statusx=== -1 ?'无效':'有效'}}</span>
            <span class="item flex"><span class="ti">是否支持自取：</span>{{shop.suportself ?'支持':'不支持'}}</span>
            <span class="item flex"><span class="ti">配送方式：</span>{{shop.isdeliver === 1?'商家自配送':'平台专送'}}</span>
            <span class="item flex"><span class="ti">预订单：</span>{{shop.bookable ? '是':'否'}}</span>
            <span class="item flex"><span class="ti">抽点方式：</span>{{shop.drawmode=== 1?'打折前':'打折后'}}</span>
            <span class="item flex"><span class="ti">打包时间：</span>{{shop.packtime}}分</span>
            <span class="item flex"><span class="ti">起送价：</span>{{shop.startpay}}元</span>
            <span class="item flex"><span class="ti">满足起送价条件:</span>{{shop.startpaymode?'折前价满足':'折后价满足'}}</span>
            <span class="item flex"><span class="ti">商户抽佣金比：</span>{{shop.coefficient}}%</span>
          </div>
        </div>
        <div class="root" style="margin-top: 10px;">
          <div class="head flex-row"><span>营销策略</span>
            <el-button type="danger" @click="setMarketing()" size="mini">编辑</el-button>
          </div>
          <div class="msg flex">
            <span class="item flex"><span class="ti">是否隐藏商家月销量：</span>{{shop.hidesales ?'是':'否'}}</span>
            <span class="item flex"><span class="ti">虚拟月销量：</span>{{shop.virtualsales || 0}}</span>
          </div>
        </div>
        <div class="root" style="margin-top: 10px;">
          <div class="head flex-row"><span>打印机管理</span>
            <span>自动打印：<el-switch v-model="shop.autoprint" @change="doBusinessPrintClick" />
           </span>
          </div>
          <div class="flex-row link" @click="wifiPrintVisiblel = true" style="cursor: pointer">
            <span>点击查看/修改wifi打印机</span><i class="el-icon-arrow-right"></i>
          </div>
        </div>
        <div class="root" style="margin-top: 10px;">
          <div class="head"><span>商家管理</span></div>
          <router-link :to="{path:'/main/busnt/add1',query:{id:$route.query.id}}">
            <div class="flex-row link"><span>点击进入修改商家详情</span><i class="el-icon-arrow-right"></i></div>
          </router-link>
        </div>
        <div class="root" style="margin-top: 10px;">
          <div class="head"><span>菜品管理</span></div>
          <router-link :to="{path:'/main/comdty/check',query:{id:$route.query.id}}">
            <div class="flex-row link"><span>点击进入商品管理</span><i class="el-icon-arrow-right"></i></div>
          </router-link>
        </div>
        <!--<div class="root" style="margin-top: 10px;">
          <div class="head">
            <span>绑定微信公众号</span>
          </div>
          <div class="flex-row link" @click="openWxMsg()">
            <span>点击查看绑定微信公众号</span><i class="el-icon-arrow-right"></i>
          </div>
        </div>-->
      </div>
    </div>
    <el-dialog title="编辑基本信息" v-dialogDrag :visible.sync="dialogTableVisible1" width="800px" :close-on-press-escap="true">
      <el-form :model="params" :rules="rules" ref="ruleForm" label-width="120px" size="small">
        <el-form-item label="门店名称" prop="name">
          <el-input v-model="params.name" placeholder="请与门店照上的名称保持一致" clearable />
        </el-form-item>
        <el-form-item label="外卖电话" required style="margin-bottom: 0">
          <el-row type="flex" v-for="(item,index) in params.wmMobile" :key="'wmMobile'+index">
            <el-form-item :prop="'wmMobile.' + index" :rules="[{required: true, message: '外卖电话未填写', trigger: 'blur'}]">
              <el-input style="width: 220px" v-model="params.wmMobile[index]" placeholder="请输入外卖联系人电话" clearable />
            </el-form-item>
            <el-form-item style="margin-left: 120px">
              <el-button class="el-text-success" v-if="index == '0'" :disabled="params.wmMobile.length >=5" type="text" @click="params.wmMobile.push('')">
                添加外卖电话({{params.wmMobile.length}}/5个)
              </el-button>
              <el-button  class="el-text-danger" v-else type="text" @click="params.wmMobile.splice(index,1)">删除</el-button>
            </el-form-item>
          </el-row>
        </el-form-item>
        <el-form-item label="联系人姓名" prop="bossName">
          <el-input v-model="params.bossName" placeholder="请输入商家联系人姓名" clearable />
        </el-form-item>
        <el-form-item label="商家电话" prop="mobile">
          <el-input style="width: 220px" v-model="params.mobile" placeholder="请输入联系人电话" clearable />
        </el-form-item>
        <el-form-item label="工作日" prop="worktoday" style="margin-bottom: 10px;">
          <el-checkbox-group v-model="params.worktoday">
            <el-checkbox style="margin-left: 0;margin-right: 30px;line-height: 32px;" v-for="(week,index) in weeks" :label="index+1" :key="'week'+index">
              {{week}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="应用时间" required>
          <el-radio v-model="timeType" label="1">24小时</el-radio>
          <el-radio v-model="timeType" label="2">自定义</el-radio>
        </el-form-item>
        <el-form-item label="自定义时间" required v-if="timeType==2">
          <el-row type="flex"> 营业时间一：
            <el-form-item prop="firstTime">
              <el-time-select placeholder="起始时间" v-model="params.firstTime[0]" :picker-options="{start: '00:00',step: '00:30',end: '24:00'}" />至
              <el-time-select placeholder="结束时间" v-model="params.firstTime[1]" :picker-options="{start: '00:00',step: '00:30',end: '24:00', minTime: params.firstTime[0]}" />
            </el-form-item>
          </el-row>
          <el-row type="flex">营业时间二：
            <el-form-item prop="secondTime" >
              <el-time-select placeholder="起始时间" v-model="params.secondTime[0]" :picker-options="{start: '00:00',step: '00:30',end: '24:00'}" />至
              <el-time-select placeholder="结束时间" v-model="params.secondTime[1]" :picker-options="{start: '00:00',step: '00:30',end: '24:00', minTime: params.secondTime[0]}" />
            </el-form-item>
          </el-row>
          <el-row type="flex"> 营业时间三：
            <el-form-item prop="thirdTime">
              <el-time-select placeholder="起始时间" v-model="params.thirdTime[0]" :picker-options="{start: '00:00',step: '00:30',end: '24:00'}" />至
              <el-time-select placeholder="结束时间" v-model="params.thirdTime[1]" :picker-options="{start: '00:00',step: '00:30',end: '24:00', minTime: params.thirdTime[0]}" />
            </el-form-item>
          </el-row>
        </el-form-item>
        <el-form-item label="商家公告" prop="content">
          <el-input type="textarea" :rows="2" v-model="params.content" placeholder="请输入商家公告" size="small" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="isloadingUpdate" @click="submitForm1('ruleForm')">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="编辑基本信息" v-dialogDrag :visible.sync="dialogTableVisible2" width="500px" :close-on-press-escape="false">
      <el-form :model="params1"  ref="ruleForm1" label-width="120px" size="small">
        <el-form-item label="是否有效商家" required>
          <el-radio v-model="params1.statusx" :label="1">有效</el-radio>
          <el-radio v-model="params1.statusx" :label="-1">无效</el-radio>
        </el-form-item>
        <el-form-item label="是否支持自取" required>
          <el-radio v-model="params1.suportself" :label="true">支持</el-radio>
          <el-radio v-model="params1.suportself" :label="false">不支持</el-radio>
        </el-form-item>
        <el-form-item label="配送方式" required>
          <el-radio v-model="params1.isdeliver" :label="0">平台专送</el-radio>
          <el-radio v-model="params1.isdeliver" :label="1">商家自配送</el-radio>
        </el-form-item>
        <el-form-item label="配送区域" v-if="params1.isdeliver === 1" prop="bdistrange" :rules="[{required: true, message: '配送区域未绘制', trigger: 'change'}]">
          <el-button size="mini" @click="cavMap()">{{params1.bdistrange ? '查看':'添加'}}配送区域</el-button>
        </el-form-item>
        <el-form-item label="自配送金额" v-if="params1.isdeliver === 1" prop="busshowps" :rules="[{required: true, message: '自配送金额未填'}]">
          <el-row type="flex">
            <el-input-number style="margin-right: 10px" v-model="params1.busshowps" :min='0' :max='9999' :precision='2' />元
          </el-row>
        </el-form-item>
        <el-form-item label="预订单" required>
          <el-radio v-model="params1.bookable" :label='true'>是</el-radio>
          <el-radio v-model="params1.bookable" :label='false'>否</el-radio>
        </el-form-item>
        <el-form-item label="抽点方式" required>
          <el-radio v-model="params1.drawmode" :label="1">打折前</el-radio>
          <el-radio v-model="params1.drawmode" :label="0">打折后</el-radio>
        </el-form-item>
        <el-form-item label="打包时间" prop="packtime" :rules="[{required: true, message: '打包时间未设置'}]">
          <el-row type="flex">
            <el-input-number style="margin-right: 10px" v-model="params1.packtime" :min='0' :max='100' :precision='0' />分
          </el-row>
        </el-form-item>
        <el-form-item label="起送价" prop="startpay" :rules="[{required: true, message: '起送价未设置'}]">
          <el-row type="flex">
            <el-input-number style="margin-right: 10px" v-model="params1.startpay" :min='0' :max='100'  :precision='2' />元
          </el-row>
        </el-form-item>
        <el-form-item label="满足起送价条件" required>
          <el-radio v-model="params1.startpaymode" :label="true">折前价满足</el-radio>
          <el-radio v-model="params1.startpaymode" :label="false">折后价满足</el-radio>
        </el-form-item>
        <el-form-item label="佣金比例" prop="coefficient" :rules="[{required: true, message: '佣金未填'}]">
          <el-row type="flex">
            <el-input-number style="margin-right: 10px" v-model="params1.coefficient" :min='0' :max='100' :precision='0' />%
          </el-row>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="isloadingUpdate" @click="submitForm2('ruleForm1')">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="绑定自动接单助手" v-dialogDrag :visible.sync="wxMsgVisible" width="500px" :append-to-body="true">
      <div class="wx-msg">
        <div class="title">绑定需要先关注自动接单助手公众号</div>
        <div class="wrap">
           <div class="sub-title">请用微信扫描下方二维码关注</div>
          <div class="img-wrap">
            <img src="~@/assets/img/qrcode.jpg" />
            <!--<pt-qrcode :qr-url='wxMsg.link' :qr-size='200' :qr-logo-size="40"
                       qr-logo="assets/img/wg-logo.png" />-->
          </div>
          <!--<div class="sub-title">或用微信访问下面链接</div>
          <div class="link flex-row-ver">
            <span class="tag-read" id="copyText">{{wxMsg.link}}</span>
            <el-button type="text" @click="copyText(wxMsg.link)">一键复制</el-button>
          </div>-->
        </div>
      </div>
    </el-dialog>
     <el-dialog title="营销策略设置" v-dialogDrag :visible.sync="dialogMarketing" width="640px" :append-to-body="true">
       <el-form :model="params2" ref="ruleForm2" label-width="180px" size="small">
        <el-form-item label="是否隐藏商家月销量" required>
          <el-radio v-model="params2.hidesales" :label='true'>是</el-radio>
          <el-radio v-model="params2.hidesales" :label='false'>否</el-radio>
        </el-form-item>
        <el-form-item label="虚拟月销量" prop="virtualsales" :rules="[{required: true, message: '设置虚拟月销量'}]">
          <el-input-number style="margin-right: 10px" v-model="params2.virtualsales" :min='0' :max='500' :precision='0' />
          <div style="marign-top: 10px;line-height: 1.2;color: #999;">设置后商家月销量 =（月销量 + 虚拟销量），如要恢复真实销量，设置0即可</div>
        </el-form-item>
      </el-form>
      <div slot="footer"><el-button type="primary" :loading="isloadingUpdate" @click="submitForm3('ruleForm2')">保存</el-button></div>
    </el-dialog>
    <el-dialog title="打印机设置" v-dialogDrag :visible.sync="wifiPrintVisiblel" width="800px">
      <print :busniessId="$route.query.id" />
    </el-dialog>
  </div>
</template>
<script>
  import AMap from 'AMap'
  import print from './components/print'
  var map
  export default {
    components: { print },
    data() {
      return {
        wifiPrintVisiblel: false, // wifi打印机
        dialogTableVisible1: false, //编辑基本信
        dialogTableVisible2: false,
        isloadingUpdate: false, //提交按钮等待
        shop: {},//商家数据
        weeks: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
        timeType: '1',
        rules1: {},
        wxMsg: {}, // 微信绑定信息
        wxMsgVisible: false, // 微信绑定信息弹窗
        params: {
          name: '', // 商家名称
          wmMobile: '', // 外卖电话
          bossName: '', // 联系人姓名
          mobile: '', // 商家电话
          worktoday: [1, 2, 3, 4, 5, 6, 7], // 工作日
          firstTime: [], // 时间一
          secondTime: [], // 时间二
          thirdTime: [], // 时间三
          content: '' // 商家简介
        },
        params1: {
          startpaymode: false, // 起送价满足方式
          bdistrange: '', // 自配送区域
          isdeliver: 0, //配送方式 0快车，1自配送
          coefficient: undefined,  //抽佣比例
          busshowps:undefined,  //自配送价格
          suportself: true,  //是否支持自取
          statusx: 1, //是否有效
          bookable: true,   // 是否预订单
          startpay: undefined, //起送价
          packtime: undefined, //打包时间
          drawmode: 1 //抽点
        },
        params2: { // 营销策略
          virtualsales: undefined, // 虚拟销量
          hidesales: false // 是否显示销量
        },
        dialogMarketing: false, // 营销策略
        rules: {
          name: [{required: true, message: '门店名称未填写', trigger: 'blur'}],
          wmMobile: [{required: true, message: '外卖电话未填写', trigger: 'blur'}],
          bossName: [{required: true, message: '商家联系人姓名未填写', trigger: 'blur'}],
          mobile: [{required: true, message: '商家电话未填写', trigger: 'blur'}],
          worktoday: [{type: 'array', required: true, message: '最少选择一天工作日', trigger: 'change'}],
          firstTime: [{type: 'array', required: true, message: '最少选择一个时间段', trigger: 'change'}],
        }
      }
    },
    methods: {
      doBusinessStateClick() {
        if (this.shop.statu) {
          this.shop.statu = false
          this.$confirm('是否确认开启营业?', '提示！', {
            confirmButtonText: '确认', cancelButtonText: '取消', type: 'info', center: true
          }).then(() => {
            this.shop.statu = true
            this.upDateshop(2)
          }).catch(() => {})
        } else {
          this.shop.statu = true
          this.$confirm('是否确认暂停营业?', '警告！', {
            confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', center: true
          }).then(() => {
            this.shop.statu = false
            this.upDateshop(2)
          }).catch(() => {

          })
        }
      },
      doBusinessPrintClick(type) {  // 是否自动打印
        this.$confirm(`是否${type? '开启': '关闭'}自动打印?`).then(() => {
          const params = {id: this.$route.query.id, autoprint: type }
          this.$http.post('/server/business/setAutoPrint',JSON.stringify(params)).then(res =>{
            if (res.data.success) {
              this.$message.success(`已${type? '开启': '关闭'}自动打印`)
            } else {
              this.shop.autoprint = !type
            }
          })
        }).catch(() => {
          this.shop.autoprint = !type
        })
      },
      toTimeForHs(str) { // 时间转换成时分格式
        if (str) {
          const arr = str.split(',')
          return [arr[0].slice(0,5),arr[1] === '23:59:59' || arr[1] =='23:59'? '24:00' :arr[1].slice(0,5)]
        } else {
          return []
        }
      },
      toTimeForYHs(time) { // 时间转换成时年月日
        if (time.length && time[0] && time[1]) {
          const arr = [`${time[0]}:00`,time[1] == '24:00' ?'23:59:59':`${time[1]}:00`]
          return arr.join(',')
        } else {
          return ''
        }
      },
      getTableList() { //获取商家信息
        let params = {id: this.$route.query.id}
        this.$http.get('/server/business/info?' + this.qs.stringify(params)).then(res => {
          if (res.data.success) {
            const row = res.data.data
            row.statu = row.statu === 0 ? true : false
            this.shop = row
            let n = () => {
              if (map) {
                if (this.shop.latitude && this.shop.longitude) {
                  map.setCenter([this.shop.longitude, this.shop.latitude])
                  var marker = new AMap.Marker({
                    position: new AMap.LngLat(this.shop.longitude, this.shop.latitude),
                    icon: 'assets/img/poi-marker-red.png',
                    offset: new AMap.Pixel(-23, -63)
                  })
                  map.add(marker)
                } else {
                  this.$message.error('商家暂无经纬度，请去完善商家信息')
                }
              } else {
                setTimeout(n, 500)
              }
            }
            n()
          }
        })
      },
      submitForm1(formName) { //提交数据
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const params = { ...this.params }
            params.id = this.$route.query.id
            if (this.timeType == '1') {
              params.firstTime = []
              params.secondTime = []
              params.thirdTime = []
            }
            params.wmMobile = params.wmMobile.length > 0 ?params.wmMobile.join(','):''
            params.firstTime = this.toTimeForYHs(params.firstTime)
            params.secondTime = this.toTimeForYHs(params.secondTime)
            params.thirdTime = this.toTimeForYHs(params.thirdTime)
            params.worktoday = params.worktoday.join(',')
            this.isloadingUpdate = true
            this.$http.post('/server/business/update', JSON.stringify(params)).then(res => {
              if (res.data.success) {
                this.$message({type: 'success', message: '修改成功'})
                this.getTableList()
                this.dialogTableVisible1 = false
              }
            }).finally(() => { this.isloadingUpdate = false })
          }
        })
      },
      cavMap() { // 绘制地图
        const option = {
          bdistrange: this.params1.bdistrange,
          searchName: '',
          lng: this.shop.longitude,
          lat: this.shop.latitude
        }
        this.$cavGdMap(option, res => {
          this.params1.bdistrange = res
        })
      },
      submitForm2(formName) { //提交数据
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const params = {...this.params1 }
            params.id = this.$route.query.id
            params.suportself = params.suportself || false
            params.statusx = this.params1.statusx || 1
            if (this.params.isdeliver === 0) {
              params.busshowps = ''
            }
            this.isloadingUpdate = true
            this.$http.post('/server/business/update', JSON.stringify(params)).then(res => {
              if (res.data.success) {
                this.$message({ type: 'success', message: '修改成功'})
                this.getTableList()
                this.dialogTableVisible2 = false
              }
            }).finally(() => { this.isloadingUpdate = false })
          }
        })
      },
      upDateshop(type) { //局部修改
        const params = {}
        let id = this.$route.query.id
        if (type == '1') {
          params.imgpath = this.shop.imgpath
          params.miniImgpath = this.shop.imgpath
        } else if (type == '2') {
          params.statu = this.shop.statu ? '0' : '1'
        }
        params.id = this.$route.query.id
        this.$http.post('/server/business/update', JSON.stringify(params)).then(res => {
          if (res.data.success) {
            this.$message({type: 'success', message: '修改成功'})
          }
        })
      },
      setBasicMsg() {  //编辑基本信息
        const row = this.shop
        const toArray = function (str) { //转整形数组
          const array = []
          str.split(',').forEach(data => {
            array.push(+data)
          })
          return array
        }
        this.dialogTableVisible1 = true
        this.$nextTick(() => {
          this.$refs['ruleForm'].resetFields()
          this.params.name = row.name || ''
          this.params.wmMobile = row.wmMobile? (row.wmMobile.indexOf(',') >-1 ?row.wmMobile.split(','):[row.wmMobile] ): ['']
          this.params.bossName = row.bossName || ''
          this.params.mobile = row.mobile || ''
          this.params.worktoday = row.worktoday ? toArray(row.worktoday) : []
          this.params.firstTime = this.toTimeForHs(row.firstTime)
          this.params.secondTime = this.toTimeForHs(row.secondTime)
          this.params.thirdTime = this.toTimeForHs(row.thirdTime)
          this.params.content = row.content || ''
          if (row.firstTime) this.timeType = '2'
        })
      },
      setDistribution() {//编辑配送信息
        this.dialogTableVisible2 = true
        this.$nextTick(() => {
          this.$refs['ruleForm1'].resetFields()
          const row = this.shop
          this.params1.busshowps = row.busshowps || undefined
          this.params1.bdistrange = row.bdistrange || ''
          this.params1.statusx = row.statusx || 1
          this.params1.isdeliver = row.isdeliver || 0
          this.params1.coefficient = row.coefficient
          this.params1.packtime = row.packtime
          this.params1.startpay = row.startpay
          this.params1.suportself = row.suportself || false
          this.params1.bookable = row.bookable || false
          this.params1.drawmode = row.drawmode || 0
          this.params1.startpaymode = Boolean(row.startpaymode)
        })
      },
      getUpLoad(img) { // 获取图片地址
        this.shop.imgpath = img
        this.upDateshop(1)
      },
      copyText(link) { // 复制url
        let oInput = document.createElement('input') // 生成一个节点
        oInput.value = link  // 你要复制的文本
        document.body.appendChild(oInput) // 插入文档
        oInput.select() // 选择对象
        document.execCommand("Copy") // 执行浏览器复制命令
        document.body.removeChild(oInput) //移除标签
        this.$message.success('链接已添加至粘贴板')
      },
      openWxMsg() { // 打开绑定微信
        this.$nextTick(() => {
          this.wxMsgVisible = true
        })
      },
      // getWxMsg() { // 查询微信绑定信息
      //   this.$http.get('/server/binding/assistant/merchant_url?businessId='+ this.$route.query.id, {headers: {isCancel: true}}).then(res => {
      //     if (res.data.success) {
      //       const wxMsg = res.data.data
      //       wxMsg.link = `http://h5.jiaowawang.cn/assistant?bcode=${wxMsg.bcode}`
      //       this.wxMsg = wxMsg
      //     }
      //   })
      // },
      setMarketing() { // 打开营销策略弹出
        this.dialogMarketing = true
        this.$nextTick(() => {
          this.$refs['ruleForm2'].resetFields()
          this.params2.virtualsales = this.shop.virtualsales
          this.params2.hidesales = this.shop.hidesales || false
        })
      },
      submitForm3(formName) { //提交数据
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const params = { ...this.params2 }
            params.id = this.$route.query.id
            this.isloadingUpdate = true
            this.$http.post('/server/business/update', JSON.stringify(params)).then(res => {
              if (res.data.success) {
                this.$message({type: 'success', message: '修改成功'})
                this.getTableList()
                this.dialogMarketing = false
              }
            }).finally(() => { this.isloadingUpdate = false })
          }
        })
      },
    },
    filters: {
      businessHours(t1,t2,t3) { // 营业时间
        let str = '全天'
        if (t1) {
          const arr1 = t1.split(',')
          str = `${arr1[0].slice(0,5)}-${arr1[1] =='23:59:59'||arr1[1] =='23:59'?'24:00':arr1[1].slice(0,5)}`
          if (t2) {
            const arr2 = t2.split(',')
            str += `、${arr2[0].slice(0,5)}-${arr2[1] =='23:59:59'||arr2[1] =='23:59'?'24:00':arr2[1].slice(0,5)}`
            if (t3) {
              const arr3 = t3.split(',')
              str += `、${arr3[0].slice(0,5)}-${arr3[1] =='23:59:59'||arr3[1] =='23:59'?'24:00':arr3[1].slice(0,5)}`
            }
          }
        }
        return str
      },
      capitalize(t1, t2, t3) {
        let arr = [t1, t2, t3]
        arr.forEach((item, index) => {
          if (!item) arr.splice(index, 1)
        })
        return arr.length > 0 ? arr.join('、') : ''
      },
      capitalize1(val) {
        const arr = ['周一', '周二', '周三', '周四' , '周五', '周六', '周日']
        if (val) {
          return val.split(',').map(item => arr[item - 1]).join('、')
        } else return ''
      }
    },
    mounted() {
      map = new AMap.Map('container', {
        center: [116.481181, 39.989792], resizeEnable: true, zoom: 16
      })
      AMap.plugin(['AMap.ToolBar', 'AMap.Scale'], function () {
        map.addControl(new AMap.ToolBar())
        map.addControl(new AMap.Scale())
      })
      if (this.$route.query.id) {
        this.getTableList()
        // this.getWxMsg()
      } else {
        this.$message({type: 'error', message: '当前页面信息有误，请从商家列表进入此页面'})
        this.$router.push({path: '/main/busnt/list'})
      }
    }
  }
</script>
<style scoped>
  @import '/css/check.css';
</style>
